package com.star.eastern.blee.utils;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.star.eastern.blee.R;

import java.util.List;

public class LogAdapter extends RecyclerView.Adapter<LogAdapter.ViewHolder>{
    private Context context;
    private List<String> mLogList;

    //定义一个内部类ViewHolder，继承自RecyclerView.ViewHolder，用来缓存子项的各个实例，提高效率
    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView msg;
        ViewHolder(View view){
            super(view);
            msg=(TextView)view.findViewById(R.id.log_text);
        }
    }

    //绑定传入的数据源
    public LogAdapter(Context context, List<String> logList){
        this.context = context;
        mLogList = logList;
    }

    //实现onCreateViewHolder方法，返回给recyclerView使用

    @Override
    public ViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_log_text,parent,false);
        return new ViewHolder(view);
    }

    //实现onBindViewHolder方法，设置子Item上各个实例
    @Override
    public void onBindViewHolder( ViewHolder holder, int position) {
        String log = mLogList.get(position);
        holder.msg.setText(log);
    }

    //返回子项个数
    @Override
    public int getItemCount() {
        return mLogList.size();
    }
}